package org.example.servlet_01.request;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;
import java.util.Set;

/**
 *  请求转发：一种在服务器内部的资源跳转方式
 *      1.步骤：
 *          1.通过request对象获取请求转发器对象：RequestDispatcher getRequestDispatcher(String path)
 *          2.使用RequestDispatcher对象来进行转发：forward(HttpServletRequest request,ServletResponse response)
 */

@WebServlet("/RequestDemo6")
public class RequestDemo6 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        System.out.println("RequestDemo6被访问啦~~");
        //浏览器地址栏url并未改变证明是在tomcat服务器内部的资源跳转
        String referer = request.getHeader("referer");
        System.out.println(referer);

        //获取从RequestDemo5转发共享区的资源
        Object msg = request.getAttribute("key");
        System.out.println(msg);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {

    }
}
